import { parse } from 'url';
import { DetailInfoItem, TableListParams } from './data.d';

function getCourierCompanyDetail(
  req: { url: any },
  res: {
    json: (
      arg0: { body: DetailInfoItem },
    ) => void;
  },
  u: any,
) {
  let new_url = u;
  if (!new_url || Object.prototype.toString.call(new_url) !== '[object String]') {
    new_url = req.url;
  }

  const params = (parse(new_url, true).query as unknown) as TableListParams;

  const { id } = params;

  const dataSource: DetailInfoItem = {
    id,
    name: '宏源大厦物业',
    telephone: '010-34567899',
    address: '北京市朝阳区酒仙桥宏源大厦',
    log_list: [
      { log_user: '张三', log_time: '2019-01-29: 22:12:10', log_info: '日志信息日志信息日志信息' },
      { log_user: '张三', log_time: '2019-01-29: 22:12:10', log_info: '日志信息日志信息日志信息' },
      { log_user: '张三', log_time: '2019-01-29: 22:12:10', log_info: '日志信息日志信息日志信息' },
    ],
  };

  const result = {
    code: 0,
    body: dataSource,
  };

  return res.json(result);
}

export default {
  'GET /courier/detail': getCourierCompanyDetail,
};
